package com.zzyl.common.ai;

import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.core.auth.Auth;
import com.baidubce.qianfan.model.chat.ChatResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BaiduAi {

//    private static final String prompt = "王扁是谁,他和王源有什么关系吗";

    @Autowired
    private BaiduAIProperties baiduAIProperties ;


    public String testBaiduAI(String prompt) {
        Qianfan qianfan = new Qianfan(Auth.TYPE_OAUTH,
                baiduAIProperties.getAccessKey(),
                baiduAIProperties.getSecretKey());

        ChatResponse response = qianfan.chatCompletion()
                .model(baiduAIProperties.getQianfanModel())
                .addMessage("user", prompt)
                .temperature(0.1)
                .maxOutputTokens(2000)
                .responseFormat("json_object")
                .execute();

        String result = response.getResult();
        return result;
    }
}
